package com.negative.activities;

import java.util.concurrent.ExecutionException;

import com.negative.logic.DownloadImageTask;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.widget.LinearLayout;

public class AdActivity extends Activity {

	String url;
	Bitmap bitmap;
	LinearLayout layout;
//	EventItem event;

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ad_layout);

		url = getIntent().getStringExtra("URL");

		layout = (LinearLayout) findViewById(R.id.ad_layout);

		DownloadImageTask task = new DownloadImageTask();
		task.execute(url);
		try {
			bitmap = task.get();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (bitmap != null) {
			BitmapDrawable background = new BitmapDrawable(bitmap);
			layout.setBackgroundDrawable(background);
			
			final Runnable r = new Runnable() {
				public void run() {
					Intent intent = new Intent(AdActivity.this,
							MainMenu.class);
					startActivity(intent);
					finish();
				}
			};
			Handler handler = new Handler();
			handler.postDelayed(r, 3000);
		} else {
			Intent intent = new Intent(AdActivity.this,
					MainMenu.class);
			startActivity(intent);
			finish();
		}
		
	}
}
